package org.jeecg.qis.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.qis.entity.QisProcheadCfg;
import org.jeecg.qis.mapper.QisProcdetailCfgMapper;
import org.jeecg.qis.mapper.QisProcheadCfgMapper;
import org.jeecg.qis.service.IQisProcheadCfgService;
import org.jeecg.common.api.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description: 过程检验配置主表
 * @Author: shaolong
 * @Date: 2022-10-10
 * @Version: V1.0
 */
@Service
public class QisProcheadCfgServiceImpl extends ServiceImpl<QisProcheadCfgMapper, QisProcheadCfg> implements IQisProcheadCfgService {

    @Autowired
    private QisProcheadCfgMapper qisProcheadCfgMapper;
    @Autowired
    private QisProcdetailCfgMapper qisProcdetailCfgMapper;

    @Override
    public void delMain(String id) {
        qisProcdetailCfgMapper.deleteByMainId(id);
        qisProcheadCfgMapper.deleteById(id);
    }

    @Override
    public void delBatchMain(Collection<? extends Serializable> idList) {
        for (Serializable id : idList) {
            qisProcdetailCfgMapper.deleteByMainId(id.toString());
            qisProcheadCfgMapper.deleteById(id);
        }
    }

    @Override
    public Result<String> edit(QisProcheadCfg qisProcheadCfg) {
        LambdaUpdateWrapper<QisProcheadCfg> eq = new LambdaUpdateWrapper<QisProcheadCfg>();
        eq.eq(QisProcheadCfg::getRecId, qisProcheadCfg.getRecId());
        boolean update = update(qisProcheadCfg, eq);
        return update ? Result.ok("修改成功!") : Result.error("修改失败!");
    }
}
